package com.ruoyi.teachingclass.mapper;

import java.util.List;

import com.ruoyi.teachingclass.domain.StudentVO;
import com.ruoyi.teachingclass.domain.TeachingClassVO;
import com.ruoyi.teachingclass.domain.Teachingclass;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * 教学班信息Mapper接口
 *
 * @author LinBei
 * @date 2025-05-16
 */
public interface TeachingclassMapper
{
    /**
     * 查询教学班信息
     *
     * @param classId 教学班信息主键
     * @return 教学班信息
     */
    public Teachingclass selectTeachingclassByClassId(Long classId);

    /**
     * 查询教学班信息列表
     *
     * @param teachingclass 教学班信息
     * @return 教学班信息集合
     */
    public List<Teachingclass> selectTeachingclassList(Teachingclass teachingclass);

    /**
     * 新增教学班信息
     *
     * @param teachingclass 教学班信息
     * @return 结果
     */
    public int insertTeachingclass(Teachingclass teachingclass);

    /**
     * 修改教学班信息
     *
     * @param teachingclass 教学班信息
     * @return 结果
     */
    public int updateTeachingclass(Teachingclass teachingclass);

    /**
     * 删除教学班信息
     *
     * @param classId 教学班信息主键
     * @return 结果
     */
    public int deleteTeachingclassByClassId(Long classId);

    /**
     * 批量删除教学班信息
     *
     * @param classIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTeachingclassByClassIds(Long[] classIds);

    public List<Teachingclass> selectTeachingclassList_handteacher(String teacherId);

    public List<Teachingclass> selectTeachingclassList_Xiteacher(String teacherId);

    public List<Teachingclass> selectTeachingclassList_teacher(String teacherId);



    @Select("SELECT " +
            "class_id, course_id, semester_id, teacher_id, " +
            "class_name, class_time, location " +
            "FROM teachingclass " +
            "WHERE teacher_id = #{teacherId}")
    @Results({
            @Result(property = "classId", column = "class_id"),
            @Result(property = "courseId", column = "course_id"),
            @Result(property = "semesterId", column = "semester_id"),
            @Result(property = "teacherId", column = "teacher_id"),
            @Result(property = "className", column = "class_name"),
            @Result(property = "classTime", column = "class_time"),
            @Result(property = "location", column = "location")
    })
    List<TeachingClassVO> selectByTeacherId(String teacherId);



    // 查询班级学生(通过cid关联)
    @Select("SELECT s.student_id, s.name as student_name, s.gender, s.major, " +
            "YEAR(s.enrollment_date) as grade, s.college " +
            "FROM stu_info s " +
            "WHERE s.cid = (SELECT cid FROM teachingclass WHERE class_id = #{classId})")
    @Results({
            @Result(property = "studentId", column = "student_id"),
            @Result(property = "studentName", column = "student_name"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "major", column = "major"),
            @Result(property = "grade", column = "grade"),
            @Result(property = "college", column = "college")
    })
    List<StudentVO> selectStudentsByClassId(Integer classId);
}
